package net.siufung.boot.datasource.querys;

import net.siufung.boot.datasource.enums.DbTypes;
import net.siufung.boot.datasource.rules.IDbType;
import net.siufung.core.utils.StringPool;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;

/**
 * @author 陈建峰
 * @since 2022/8/12 5:17 下午
 */
public class MySql5Query extends AbstractDbQuery {

    public static final MySql5Query INSTANCE = new MySql5Query();

    @Override
    public String getTablesSql() {
        return "show table status WHERE 1=1 ";
    }

    @Override
    public String getTableFieldsSql() {
        return "show full fields from `%s`";
    }

    @Override
    public String getTableName() {
        return "NAME";
    }

    @Override
    public String getTableComment() {
        return "COMMENT";
    }

    @Override
    public String getFieldName() {
        return "FIELD";
    }

    @Override
    public String getFieldType() {
        return "TYPE";
    }

    @Override
    public String getFieldComment() {
        return "COMMENT";
    }

    @Override
    public String getFieldKey() {
        return "KEY";
    }

    @Override
    public String getFieldEmptyKey() {
        return StringPool.NULL.toUpperCase(Locale.ROOT);
    }

    @Override
    public IDbType getDbType() {
        return DbTypes.MYSQL_5;
    }

    @Override
    public boolean isKeyIdentity(ResultSet results) throws SQLException {
        return "auto_increment".equals(results.getString("Extra"));
    }
}
